// 企业用汽
<template>
  <div class="enterprise">
    <div class="operate card">
      <!-- <div >时间维度:</div> -->
      <div class="timedimension">
        <el-select style="width:70px" v-model="t_value" @change="t_change">
          <el-option v-for="item in options_t_type" :key="item.value" :label="item.label" :value="item.value"></el-option>
        </el-select>
      </div>
      <!-- <div>时间区间:</div> -->
      <div class="picker">
        <el-date-picker style="width:180px" v-model="s_time" :editable="false" :clearable="false" :type="d_type" :format="v_type" :value-format="v_type" :picker-options="pickerOptions"></el-date-picker>
      </div>
      <div class="hidden-xs-only">
        <i class="el-icon-minus"></i>
      </div>
      <div class="picker">
        <el-tooltip :content="content" placement="top">
          <el-date-picker style="width:180px" v-model="e_time" :editable="false" :clearable="false" :type="d_type" :format="v_type" :value-format="v_type" :picker-options="pickerOptions"></el-date-picker>
        </el-tooltip>
      </div>
      <div>
        <el-button type="primary" @click="t_button">查询</el-button>
      </div>
      <div class="export">
        <el-tooltip content="导出" placement="top">
          <el-button type @click="t_export">
            <i style="color:#0780EDfont-size:20px" class="iconfont icon-daochu"></i>
          </el-button>
        </el-tooltip>
      </div>
    </div>
    <el-row :gutter="24">
      <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
        <div class="card">
          <Mtitle title="各车间用汽占比"></Mtitle>
          <ecl v-loading="ec_l_loading" v-no-data="ec_l_no_data" style="height:400px" :ecdata="ec_l_data" unit="t" width="100%" height="100%"></ecl>
        </div>
      </el-col>
      <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
        <div class="card">
          <Mtitle :title="qi_title"></Mtitle>
          <ecline v-loading="ec_r_loading" v-no-data="ec_r_no_data" style="height:400px" :unit="qi_unit" :ecdata="ec_r_data" width="100%" height="100%"></ecline>
        </div>
      </el-col>
    </el-row>
    <el-row class="card" :gutter="0">
      <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
        <Mtitle title="用汽详情"></Mtitle>
        <tb tableTitle="tb_008" :tableData="tableData" v-loading="table_loading" id="tab"></tb>
      </el-col>
    </el-row>
  </div>
</template>
<script>
import day from "@/utils/day.js"
import Mtitle from '@/components/Mtitle'
import ecl from '@/components/echarts/ec_pie'
import ecline from '@/components/echarts/ec_line'
import tb from '@/components/table'
export default {
  components: {
    Mtitle,
    ecl,
    ecline,
    tb
  },
  watch: {
  },
  data() {
    return {
      content: '查询时间跨度最大为24小时',
      qi_title: '蒸汽负荷情况',
      qi_unit: 't/h',
      tableData: [],
      // 初始开始时间
      s_time: "",
      // 初始结束时间
      e_time: "",
      // 初始日期格式
      v_type: "yyyy-MM-dd HH:mm",
      // 初始显示类型
      d_type: "datetime",
      // 日   月  年 
      t_value: 1,
      options_t_type: [
        {
          value: 1,
          label: "日"
        },
        {
          value: 2,
          label: "月"
        },
        {
          value: 3,
          label: "年"
        }
      ],
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now()
        }
      },
      // 获取年月日初始化时间对象
      CustTime: {},
      ec_l_data: [],
      ec_l_loading: true,
      ec_l_no_data: false,
      ec_r_data: [],
      ec_r_loading: true,
      ec_r_no_data: false,
      // ec_b_data: [],
      ec_b_loading: true,
      query_button_loading_num: 0,
      table_loading: true,
      export_s_time: '',
      export_e_time: '',
      export_value: ''
    }
  },
  computed: {
  },
  watch: {
    query_button_loading_num(n, o) {
      if (n === 4) {
      }
    }
  },
  mounted() {  this.s_e = day.init_value(this.d_type)
    this.s_time = this.s_e.s
    this.e_time = this.s_e.e
    this.export_s_time = this.s_time
    this.export_e_time = this.e_time
    this.export_value = this.t_value
    this.getWorkshopRatio()
    this.getsteamLoad()
    // this.getVapourCurve()
    this.findSteam()

  },
  created() {
    // 初始化默认时间

    // 获取出事日期
    // this.$nextTick(() => {
    //   this.getCustTime()
    // })

  },
  methods: {
    //各车间用汽量占比
    getWorkshopRatio() {
      this.$axios
        .post(this.Eelec + "/steamStatistics/getWorkshopRatio", {
          custId: sessionStorage.getItem("custId"),
          downsample: this.t_value,
          endDate: this.t_value == 1 ? this.e_time + ':00' : this.e_time,
          startDate: this.t_value == 1 ? this.s_time + ':00' : this.s_time
        })
        .then(res => {
          this.ec_l_loading = false
          if (res.data.code == 200) {
            if (res.data.data.steamMonthNumList && res.data.data.steamMonthNumList.length) {
              this.ec_l_data = res.data.data.steamMonthNumList.map((item, index) => {
                return {
                  name: item.name,
                  value: item.steamAmount
                }
              })
            } else {
              this.ec_l_no_data = true
              this.ec_l_data = []
            }
          } else {
            this.ec_l_no_data = true
            this.ec_l_data = []
          }
        })
        .catch(err => {
          console.log(err)
        })
    },
    //蒸汽负荷情况
    getsteamLoad() {
      this.$axios
        .post(this.Eelec + "/steamStatistics/getsteamLoad", {
          downsample: this.t_value,
          custId: sessionStorage.getItem("custId"),
          endDate: this.t_value == 1 ? this.e_time + ':00' : this.e_time,
          startDate: this.t_value == 1 ? this.s_time + ':00' : this.s_time
        })
        .then(res => {
          this.ec_r_loading = false
          if (res.data.code == 200) {
            if (res.data.data.dataRespFs) {
              this.ec_r_data = res.data.data.dataRespFs.map((item, index) => {
                return {
                  name: item.name,
                  value: item.dataResp
                }
              })
            } else {
              this.ec_r_no_data = true
              this.ec_r_data = []
            }
          } else {
            this.ec_r_data = []
            this.ec_r_no_data = true
          }
        })
        .catch(err => {
          console.log(err)
        })
    },
    //用汽曲线
    getVapourCurve() {
      this.$axios
        .post(this.Eelec + "/steamStatistics/getVapourCurve", {
          downsample: this.t_value,
          custId: sessionStorage.getItem("custId"),
          endDate: this.t_value == 1 ? this.e_time + ':00' : this.e_time,
          startDate: this.t_value == 1 ? this.s_time + ':00' : this.s_time
        })
        .then(res => {
          this.ec_r_loading = false
          if (res.data.code == 200) {
            if (res.data.data) {
              this.ec_r_data = [
                {
                  name: '用汽量',
                  value: res.data.data
                }
              ]
            } else {
              this.ec_r_data = []
            }
          } else {
            this.ec_r_data = []
          }
        })
        .catch(err => {
          console.log(err)
        })
    },
    //企业用汽详情
    findSteam() {
      this.$axios
        .post(this.Eelec + "/steamStatistics/findSteam", {
          custId: sessionStorage.getItem("custId"),
          downsample: this.t_value,
          endDate: this.t_value == 1 ? this.e_time + ':00' : this.e_time,
          startDate: this.t_value == 1 ? this.s_time + ':00' : this.s_time
        })
        .then(res => {
          this.table_loading = false
          if (res.data.code == 200) {
            this.tableData = res.data.data
          }
        })
        .catch(err => {
          console.log(err)
        })
    },
    t_export() {
      this.$axios
        .post(this.Eelec + "/steamStatistics/getElectricExcel", {
          downsample: this.export_value,
          custId: sessionStorage.getItem("custId"),
          endDate: this.export_value == 1 ? this.export_e_time + ':00' : this.export_e_time,
          startDate: this.export_value == 1 ? this.export_s_time + ':00' : this.export_s_time
        })
        .then(res => {
          if (res.data.code === 200) {
            if (res.data.data) {
              window.location.href = res.data.data
              this.$message({
                message: "导出成功",
                type: "success"
              })
            }
          }
        })
    },
    // 点击查询
    t_button() {
      day.s_e(this.s_time, this.e_time, this.t_value)
        .then(() => {
          this.export_s_time = this.s_time
          this.export_e_time = this.e_time
          this.export_value = this.t_value
          this.query_button_loading_num = 0,
            this.ec_l_loading = true,
            this.ec_r_loading = true,
            this.ec_b_loading = true,
            this.table_loading = true
          this.getWorkshopRatio()
          if (this.t_value === 1) {
            this.qi_title = '蒸汽负荷情况'
            this.qi_unit = 't/h'
            this.getsteamLoad()
          } else {
            this.qi_title = '用汽情况'
            this.qi_unit = 't'
            this.getVapourCurve()
          }
          this.findSteam()
        })
        .catch(() => { })
    },
    // 切换年月日
    t_change(n) {
      if (n === 1) {
        this.content = '查询时间跨度最大为24小时'
      }
      if (n === 2) {
        this.content = '查询时间跨度最大为31天'
      }
      if (n === 3) {
        this.content = '查询时间跨度最大为12个月'
      }
      this.v_type = day.change_type(n).v
      this.d_type = day.change_type(n).d
      this.s_e = day.init_value(this.d_type)
      this.s_time = this.s_e.s
      this.e_time = this.s_e.e
    }
  }
}
</script>
 <style scoped lang='scss'>
</style>
